package org.mansion.api.dishes;

import static org.junit.Assert.fail;

import java.math.BigDecimal;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import com.esotericsoftware.minlog.Log;
import com.mdc.mansion.common.exception.BusinessException;
import com.mdc.mansion.common.response.Result;
import com.mdc.mansion.common.response.ResultCode;
import com.mdc.mansion.common.util.I18nUtil;
import com.mdc.mansion.core.modules.order.RestaurantOrderService;
import com.mdc.mansion.dataaccess.modules.order.entity.RestaurantOrder;
import com.mdc.mansion.dataaccess.modules.order.vo.RestaurantOrderVo;

import net.sf.json.JSONObject;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:application-config.xml"})
public class Bill_Test_case {
	
	@Autowired
	private RestaurantOrderService restaurantOrderService;

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testQueryBillOrder() {
		
		RestaurantOrderVo restaurantOrderVo = null;
		Map<String,Object> resultMap = null;
		try
		{
			restaurantOrderVo = new RestaurantOrderVo();
//			restaurantOrderVo.setRestaurantId(restaurant.getId());
			/**订单号**/
			restaurantOrderVo.setId("d14485facd224d5f9586da3941a6b9c1");
			
			resultMap = restaurantOrderService.queryByOrder(restaurantOrderVo);
			
			if( null == resultMap || 0 == resultMap.size())
			{
				/** 未查询到订单信息 **/
				Log.info("未查询到订单信息");
			}
			JSONObject object = JSONObject.fromObject(resultMap);
        	Log.info(object.toString());
        	
		}catch(BusinessException e)
		{
			Log.error(I18nUtil.getMessage(e.getMessage()));
			fail("Not yet implemented");
		}catch(Exception e)
		{
			Log.error(e.getMessage());
			fail("Not yet implemented");
		}
		
		
	}

	@Test
	public void testBillCheckOut() {
		
		RestaurantOrder restaurantOrder = new RestaurantOrder();
		try
		{
			restaurantOrder.setId("1beaa193de6345e5b2283959fe8709f6");
			restaurantOrder.setRebate(new BigDecimal(90));
			restaurantOrder.setAbatement(new BigDecimal(5));
			restaurantOrder.setServicePrice(new BigDecimal(5));
			restaurantOrder.setServiceTariffing(new BigDecimal(3));
			restaurantOrder.setReceivablePrice(new BigDecimal(10));
			restaurantOrder.setActualReceivePrice(new BigDecimal(34.5));
			restaurantOrderService.billCheckOut(restaurantOrder);
			
			
		}catch(BusinessException e) 
		{
			Log.error(e.getMessage());
			fail("Not yet implemented");
		}catch(Exception e)
		{
			/**结账失败,请联系客服**/
			Log.error(e.getMessage());
			fail("Not yet implemented");
		}
		
		
	}

	@Test
	public void testRefund() {
		RestaurantOrder restaurantOrder = new RestaurantOrder();
		try
		{
			restaurantOrder.setId("4826387e901e42a6aebb84977eb2b3f");
			restaurantOrder.setRefundPrice(new BigDecimal(20));
			restaurantOrder.setRestaurantId("008ee168fad5410fb446afa71b683316");
			restaurantOrderService.refund(restaurantOrder);
			
			
		}catch(BusinessException e) 
		{
			Log.error(e.getMessage());
			fail("Not yet implemented");
		}catch(Exception e)
		{
			/**结账失败,请联系客服**/
			Log.error(e.getMessage());
			fail("Not yet implemented");
		}
	}

	@Test
	public void testHistory() {
		try{
			
			Map<String,Object> resultMap = null;
			RestaurantOrderVo restaurantOrderVo = new RestaurantOrderVo();
			restaurantOrderVo.setQueryDate("20180129");
			restaurantOrderVo.setRestaurantId("008ee168fad5410fb446afa71b683316");
			restaurantOrderVo.setPageSize("10");
			restaurantOrderVo.setPageNo("0");
			resultMap = restaurantOrderService.history(restaurantOrderVo);
			JSONObject object = JSONObject.fromObject(resultMap);
        	Log.info(object.toString());
		
		}catch(Exception e)
		{
			Log.error(e.getMessage());
			fail("Not yet implemented");
		}
	}
	
	@Test
	public void testOrderGet()
	{
		RestaurantOrder restaurantOrder = new RestaurantOrder();
		restaurantOrder.setRestaurantTableId("");
//		restaurantOrderService.billCheckOut(restaurantOrder);
	}
	
	
	@Test
	public void testI18()
	{
		String Str = I18nUtil.getMessage("order.refund.fail.exception");
		Str.replace("/", "");
		Log.info("test: >>>>>>>> "+Str);
	}

}
